package com.jingtuo.android.common.utils;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;

public class BaiduUtils {

	public static final String ENCODING = "utf-8";
	
	public static final String TYPE_IMAGE = "baiduimage";
	
	public static final String IMAGE_URI = "http://image.baidu.com/i";
	
	public static final String PARAM_NAME_TN = "tn";
	public static final String PARAM_NAME_IPN = "ipn";
	public static final String PARAM_NAME_CT = "ct";
	public static final String PARAM_NAME_CL = "cl";
	public static final String PARAM_NAME_LM = "lm";
	public static final String PARAM_NAME_ST = "st";
	public static final String PARAM_NAME_FM = "fm";
	public static final String PARAM_NAME_FR = "fr";
	public static final String PARAM_NAME_SF = "sf";
	public static final String PARAM_NAME_FMQ = "fmq";
	public static final String PARAM_NAME_PV = "pv";
	public static final String PARAM_NAME_IC = "ic";
	public static final String PARAM_NAME_NC = "nc";
	public static final String PARAM_NAME_Z = "z";
	public static final String PARAM_NAME_SE = "se";
	public static final String PARAM_NAME_SHOWTAB = "showtab";
	public static final String PARAM_NAME_FB = "fb";
	public static final String PARAM_NAME_WIDTH = "width";
	public static final String PARAM_NAME_HEIGHT = "height";
	public static final String PARAM_NAME_FACE = "face";
	public static final String PARAM_NAME_ISTYPE = "istype";
	public static final String PARAM_NAME_IE = "ie";
	public static final String PARAM_NAME_WORD = "word";
	public static final String PARAM_NAME_ACTION = "action";
	
	public static String search(String type, String word){
		List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
		String result = "";
		try {
			parameters.add(new BasicNameValuePair(PARAM_NAME_TN, TYPE_IMAGE));
			parameters.add(new BasicNameValuePair(PARAM_NAME_IPN, "r"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_CT, "201326592"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_CL, "2"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_LM, "-1"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_ST, "-1"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_FM, "index"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_FR, ""));
			parameters.add(new BasicNameValuePair(PARAM_NAME_SF, "1"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_FMQ, ""));
			parameters.add(new BasicNameValuePair(PARAM_NAME_PV, ""));
			parameters.add(new BasicNameValuePair(PARAM_NAME_IC, "0"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_NC, "1"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_Z, ""));
			parameters.add(new BasicNameValuePair(PARAM_NAME_SE, "1"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_SHOWTAB, "0"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_FB, "0"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_WIDTH, ""));
			parameters.add(new BasicNameValuePair(PARAM_NAME_HEIGHT, ""));
			parameters.add(new BasicNameValuePair(PARAM_NAME_FACE, "0"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_ISTYPE, "2"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_IE, "utf-8"));
			parameters.add(new BasicNameValuePair(PARAM_NAME_WORD, word));

			UrlEncodedFormEntity encodedFormEntity = new UrlEncodedFormEntity(parameters, ENCODING);
			result = HttpUtils.doPost(IMAGE_URI, encodedFormEntity);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	
	
	
}
